﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Main_Inventory_ViewPurchaseOrder : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string strsql = "";
    DataTable DTMain = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindCustomData();
        }
    }  
    protected void BindCustomData()
     {
        DataTable DTMain = DU.getdatausingprocedure("USP_IVC_PO_SERVICEINVOICE_Detail");
        grdDisplay.DataSource = DTMain;
        grdDisplay.DataBind();
     }

    protected void grdDisplay_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdDisplay.PageIndex = e.NewPageIndex;
        BindCustomData();
    }
    
    protected void grdDisplay_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "editpo")
        {
            GridViewRow row=(GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
            int d = row.RowIndex;
            string key    = e.CommandArgument.ToString();
            string pono   = grdDisplay.Rows[d].Cells[1].Text.ToString();
            string podate = grdDisplay.Rows[d].Cells[2].Text.ToString();
            string client = grdDisplay.Rows[d].Cells[3].Text.ToString();
            Response.Redirect("PurchaseOrderEdit.aspx?Poid=" + key.ToString() + "&PONO="+ pono +"&PODate="+ podate +"&Client="+ client +"");
            //Response.Write("Poid=" + key.ToString() + "<br /> PONO=" + pono + "<br /> PODate=" + podate + "<br /> Client=" + client + "");
        }
    }
    protected void grdDisplay_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ////DataTable DT = (DataTable)grdDisplay.DataSource;
            //string PoId = grdDisplay.DataKeys[e.Row.RowIndex].Value.ToString();
            //strsql = " Select Status from ACC_POMAIN where POID='" + PoId + "'";
            //DataTable DT = DU.getdata(strsql);
      
            //if (DT.Rows.Count > 0)
            //{
            //        if (DT.Rows[0]["Status"].ToString() == "2")
            //        {
            //            e.Row.Cells[6].FindControl("lnkEdit").Visible = false;
            //        }
            //        else
            //        {
            //            e.Row.Cells[6].FindControl("imgLock").Visible = false;
            //        }            
            //}
        }
    }
    protected void custPager_PageChanged(object sender, CustomPageChangeArgs e)
    {
        grdDisplay.PageSize = e.CurrentPageSize;
        grdDisplay.PageIndex = e.CurrentPageNumber;
        BindCustomData(); 
    }
    protected void grdDisplay_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.Pager)
        {
            if (e.Row.RowState == DataControlRowState.Alternate)
            {
                e.Row.Attributes.Add("onmouseover", "this.className='rowhover'");
                e.Row.Attributes.Add("onmouseout", "this.className='gridview_alternate'");
                //e.Row.Attributes.Add("onclick", "this.className='rowselected'");
            }
            else if (e.Row.RowState == DataControlRowState.Normal)
            {
                e.Row.Attributes.Add("onmouseover", "this.className='rowhover'");
                e.Row.Attributes.Add("onmouseout", "this.className='gridviewitem'");
                //e.Row.Attributes.Add("onclick", "this.className='rowselected'");
            }
        }
    }
}
